package webserver;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;

@SuppressWarnings("serial")
public class Request extends HashMap<String, String> {
	private String method;
	private URI requestURI;
	private String version;

	public Request(SocketInputStream in) throws IOException, URISyntaxException {
		String line = in.readLine();
		if (line != null) {
			String[] strArr = line.split(" ", 3);
			method = strArr[0];
			requestURI = new URI(strArr[1]);
			version = strArr[2];
		}

		// Read remaining headers and place them in the hashmap
		while ((line = in.readLine()) != null) {
			int colonIndex = line.indexOf(':');
			if (colonIndex > 0) {
				put(line.substring(0, colonIndex),
						line.substring(colonIndex + 1));
			}
		}
	}

	String getMethod() {
		return method;
	}

	URI getRequestURI() {
		return requestURI;
	}

	String getVersion() {
		return version;
	}
}
